<!--
 * @Author: cmyshare cmyshare@163.com
 * @Date: 2023-10-14 22:38:36
 * @LastEditors: cmyshare cmyshare@163.com
 * @LastEditTime: 2023-10-14 23:54:12
 * @FilePath: \Open-Vue\06_数据代理\2.何为数据代理.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8" />
		<title>何为数据代理</title>
	</head>
	<body>
		<!-- 数据代理：通过一个对象代理对另一个对象中属性的操作（读/写）-->
		<script type="text/javascript" >
			let obj = {x:100}
			let obj2 = {y:200}
			Object.defineProperty(obj2,'x',{
				// 获取
				get(){
					return obj.x
				},
				// 修改
				set(value){
					obj.x = value
				}
			})
		</script>
	</body>
</html>